<template>
  <div id="app" v-cloak>
    <van-list v-model="loading" :finished="finished" finished-text="暂无更多数据" @load="onLoad" >
      <van-cell v-for="(item, index) in items" :key="index" :title="item.name" :value="item.created_at"/>
    </van-list>
</div>
</template>
<script>
export default {
  data () {
    return {
      items: [],
      finished: false,
      loading: false,
      page: 1,
      limit: 16,
    }
  },
   mounted: function() {
    this.fetch_items();
  },
  methods: {
    onLoad: function() {
      this.page += 1;
      this.fetch_items();
    },
    fetch_items: function() {

      var that = this;
      let floorID = sessionStorage.getItem('floorID');
      this.$http.get(`/api/spaces/getSpacesList?floorId=${floorID}&limit=${this.limit}&page=${this.page}`,{
        headers:{ 'Authorization':localStorage.getItem('token'),}
      }).then(res =>{
        if(res.data.errcode == 0){
          that.loading = false; 
          that.items.push(...res.data.data.list);
        if(that.items.length >= res.data.data.total){
          that.finished = true;
        }
        }
      })
    }
  }
}
</script>